class Solution {
public:
    int minEatingSpeed(vector<int>& piles, int h) {
        int Max = 0;
        for(int& x : piles){
            Max = max(x,Max);
        }
        
        int l = 1;
        int r = Max;
        while(l <= r){
            int m = l + (r - l) / 2;
            int time = 0;
            
            for(int& x : piles){
                time += (x - 1) / m + 1;
            }
            if(time > h){
                l = m + 1;
            }else{
                r = m - 1;
            }
        }
        return l;
    }
};
